Add a local_only property to GtkFileChooserEntry
authorFederico Mena Quintero <federico@novell.com>
Wed, 21 Jan 2009 03:16:46 +0000 (03:16 +0000)
committerFederico Mena Quintero <federico@src.gnome.org>
Wed, 21 Jan 2009 03:16:46 +0000 (03:16 +0000)
Patch by Carlos Garnacho <carlos@imendio.com> - add a local_only
property to GtkFileChooserEntry:

* gtk/gtkfilechooserentry.c (struct _GtkFileChooserEntry): Add a
local_only field.
(_gtk_file_chooser_entry_init): Default to local_only being true.
(start_explicit_completion): Don't allow completion of non-native
files if local_only is turned on.
(start_loading_current_folder): Don't start loading non-native
folders if local_only is turned on.
(_gtk_file_chooser_entry_set_local_only): New function.
(_gtk_file_chooser_entry_get_local_only): New function.

* gtk/gtkfilechooserentry.h (_gtk_file_chooser_entry_set_local_only,
_gtk_file_chooser_entry_get_local_only): New prototypes.

* gtk/gtkfilechooserdefault.c (set_local_only): Set the local_only
property on the entry.

Signed-off-by: Federico Mena Quintero <federico@novell.com>
svn path=/trunk/; revision=22156

ChangeLog
gtk/gtkfilechooserdefault.c
gtk/gtkfilechooserentry.c
gtk/gtkfilechooserentry.h

index 3b868c2dcecc04bb7421622936fbb753895aa94e..8c91c4508c25f3d319e86f1476a1ccf2a2968f4d 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,4 @@
-2009-01-15  Federico Mena Quintero  <federico@novell.com>
+2009-01-20  Federico Mena Quintero  <federico@novell.com>
 
        http://bugzilla.gnome.org/show_bug.cgi?id=545980 -
        GtkFileChooserEntry should handle URIs
        discard_current_folder().
        (reload_current_folder): Use discard_current_folder().
 
+       Patch by Carlos Garnacho <carlos@imendio.com> - add a local_only
+       property to GtkFileChooserEntry:
+
+       * gtk/gtkfilechooserentry.c (struct _GtkFileChooserEntry): Add a
+       local_only field.
+       (_gtk_file_chooser_entry_init): Default to local_only being true.
+       (start_explicit_completion): Don't allow completion of non-native
+       files if local_only is turned on.
+       (start_loading_current_folder): Don't start loading non-native
+       folders if local_only is turned on.
+       (_gtk_file_chooser_entry_set_local_only): New function.
+       (_gtk_file_chooser_entry_get_local_only): New function.
+
+       * gtk/gtkfilechooserentry.h (_gtk_file_chooser_entry_set_local_only,
+       _gtk_file_chooser_entry_get_local_only): New prototypes.
+
+       * gtk/gtkfilechooserdefault.c (set_local_only): Set the local_only
+       property on the entry.
+
 2009-01-20  Matthias Clasen  <mclasen@redhat.com>
 
        * gtk/gtk.symbols:
index e9ee8e1fdd35082ff82a56104a500bc24d7f7aa7..3492c698490e8df13504496b3df23eab952a6bd9 100644 (file)
@@ -5334,6 +5334,8 @@ set_local_only (GtkFileChooserDefault *impl,
     {
       impl->local_only = local_only;
 
+      _gtk_file_chooser_entry_set_local_only (GTK_FILE_CHOOSER_ENTRY (impl->location_entry), local_only);
+
       if (impl->shortcuts_model && impl->file_system)
        {
          shortcuts_add_volumes (impl);
index 07bee3b9a906b93e5419d2c07e95e95c8c5919ba..c25de12c7b555dee97c730069acde30f44361c63 100644 (file)
@@ -79,6 +79,7 @@ struct _GtkFileChooserEntry
   guint has_completion : 1;
   guint in_change      : 1;
   guint eat_tabs       : 1;
+  guint local_only     : 1;
 };
 
 enum
@@ -194,6 +195,8 @@ _gtk_file_chooser_entry_init (GtkFileChooserEntry *chooser_entry)
   GtkEntryCompletion *comp;
   GtkCellRenderer *cell;
 
+  chooser_entry->local_only = TRUE;
+
   g_object_set (chooser_entry, "truncate-multiline", TRUE, NULL);
 
   comp = gtk_entry_completion_new ();
@@ -1107,6 +1110,16 @@ start_explicit_completion (GtkFileChooserEntry *chooser_entry)
       return;
     }
 
+  if (chooser_entry->local_only
+      && !g_file_is_native (chooser_entry->current_folder_file))
+    {
+      beep (chooser_entry);
+      pop_up_completion_feedback (chooser_entry, _("Only local files can be selected"));
+
+      chooser_entry->load_complete_action = LOAD_COMPLETE_NOTHING;
+      return;
+    }
+
   if (chooser_entry->current_folder
       && _gtk_folder_is_finished_loading (chooser_entry->current_folder))
     {
@@ -1366,6 +1379,10 @@ start_loading_current_folder (GtkFileChooserEntry *chooser_entry)
       chooser_entry->file_system == NULL)
     return;
 
+  if (chooser_entry->local_only
+      && !g_file_is_native (chooser_entry->current_folder_file))
+    return;
+
   g_assert (chooser_entry->current_folder == NULL);
   g_assert (chooser_entry->load_folder_cancellable == NULL);
 
@@ -1826,3 +1843,16 @@ _gtk_file_chooser_entry_select_filename (GtkFileChooserEntry *chooser_entry)
   gtk_editable_select_region (GTK_EDITABLE (chooser_entry), 0, (gint) len);
 }
 
+void
+_gtk_file_chooser_entry_set_local_only (GtkFileChooserEntry *chooser_entry,
+                                        gboolean             local_only)
+{
+  chooser_entry->local_only = local_only;
+  clear_completions (chooser_entry);
+}
+
+gboolean
+_gtk_file_chooser_entry_get_local_only (GtkFileChooserEntry *chooser_entry)
+{
+  return chooser_entry->local_only;
+}
index 2818fd9da7d4d45283fa45486fe03b3828b89f57..a9c9f8388cbfbd4c7c1955f1558a4c875d15caeb 100644 (file)
@@ -48,6 +48,9 @@ const gchar *      _gtk_file_chooser_entry_get_file_part      (GtkFileChooserEnt
 gboolean           _gtk_file_chooser_entry_get_is_folder      (GtkFileChooserEntry *chooser_entry,
                                                               GFile               *file);
 void               _gtk_file_chooser_entry_select_filename    (GtkFileChooserEntry *chooser_entry);
+void               _gtk_file_chooser_entry_set_local_only     (GtkFileChooserEntry *chooser_entry,
+                                                               gboolean             local_only);
+gboolean           _gtk_file_chooser_entry_get_local_only     (GtkFileChooserEntry *chooser_entry);
 
 G_END_DECLS